package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.Bed;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NursingProjectServiceimpl implements NursingProjectService {
 @Autowired
 private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> sellectByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);//分页查询插件
        Page<NursingProjectVo> page = nursingProjectMapper.sellectByPage(name, status);
        PageResponse<NursingProjectVo> pageResponse = PageResponse.of(page,NursingProjectVo.class);
        return pageResponse;
    }

    @Override
    public void insert(NursingProjectDto dto) {
        //这个写法是spring工具自带的
       /* NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(dto,nursingProject);*/

        //这个是hutool工具类，两者功能一样
        NursingProject nursingProject = BeanUtil.toBean(dto, NursingProject.class);
        nursingProjectMapper.insert(nursingProject);

    }

    @Override
    public NursingProjectVo sellectById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.sellectById(id);
        //这个写法是spring工具自带的,把entity转成vo
        NursingProjectVo npv = new NursingProjectVo();
        BeanUtils.copyProperties(nursingProject,npv);
        return npv;
    }

    /**
     * 更新护理项目信息
     *
     * @param nursingProjectDTO 护理项目数据传输对象
     */
    @Override
    public void update(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id, status);
    }

    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }
}
